/*
 * 
 *方法的整理与重构
 *
 *
 */

//定义app参数名称，并加载其它模块
var authApp=angular.module('authapp', ["ngCookies",'ngFileUpload','ui.bootstrap']);

//此为定位页面所用
authApp.value('page','expert_info');

/*controller部分*/

//定义父controller，主要用于controller之间传递信息
authApp.controller("fcontroller",function($scope,$http){
	//
	//****与分页相关的****
	//
})


//主要操作controller
authApp.controller("expertListController",function($scope,$http){
	//**********主体方法
	//设置分页初始参数（最好与$scope.currentPage和$scope.itemsPerPage一致！！！！//这边之所以$scope.pageNumber=0是因为后台接口第一页为0）

	var queryAuthExpertInfoByOneId=apis.queryAllIndexTarget;//！！！should edit
	$scope.queryMain=function(){
		$http({
			method:'get',
			url:queryAuthExpertInfoByOneId,
			data:{},
		}).success(function(response){
			if(response.code=="000000"){
				$scope.expertcode=response.data.s_expert_code;
				$scope.expertname=response.data.s_name;
				$scope.title=response.data.s_title;
				$scope.post=response.data.s_post;
				$scope.field=response.data.s_field;
				$scope.officephone=response.data.s_officephone;
				$scope.phone=response.data.s_phone;
				$scope.email=response.data.s_email;
				$scope.workunit=response.data.s_workunit;
				$scope.createtime=response.data.s_create_time;
			}else{
				alert(response.errorMsg);
			}
		}).error(function(){
			alert("网络出现故障，请确认网络是否连接");
		})
	}

	$scope.queryMain();
	
	/*下面为自已编辑部分*/
	/*
	 * 
	 * 其它操作方法
	 * 
	 */
	
	//清空专家信息
	$scope.clearInfo=function(){	
		$scope.title="";
		$scope.post="";
		$scope.field="";
		$scope.officephone="";
		$scope.phone="";
		$scope.email="";
		$scope.workunit="";
		$scope.createtime="";
	}

	//修改专家信息
	$scope.updateAuthExpertBySessionId=function(){
		if(window.confirm("是否确认修改？")){
			var rJson={'code':$scope.expertcode,
						'name':$scope.expertname,
						'title':$scope.title,
						'post':$scope.post,
						'field':$scope.field,
						'officephone':$scope.officephone,
						'phone':$scope.phone,
						'email':$scope.email,
						'workunit':$scope.workunit
						};
			$http({
				method:'post',
				url:apis.updataExpertInfo,
				data:rJson,
			}).success(function(response){
				if(response.code=="000000"){
					$scope.queryMain();
					$scope.clearInfo();
				}else{
					alert(response.errorMsg);
				}
			}).error(function(){
				alert("服务器打瞌睡了，请稍等！");
			})
		}
	}

})
